const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    textA: '', //评价内容
    productCommentId: '',
    img_arr: [],
    formdata: '',
    flag3: 2,
    flag: 2,
    haoping: '满意',
    haoping1: '满意',
    haoping2: '满意',
    localImg: '',
    pics: [],
    count: [1, 2, 3, 4, 5, 6, 7, 8, 9],
    isShow: true,
    billid: '', //账单id
    resid: '', //餐厅id

    start: [{
        img1: '../../images/img1.png',
        img: '../../images/img.png',
        id: 1
      },
      {
        img1: '../../images/img1.png',
        img: '../../images/img.png',
        id: 2
      },
      {
        img1: '../../images/img1.png',
        img: '../../images/img.png',
        id: 3
      },
      {
        img1: '../../images/img1.png',
        img: '../../images/img.png',
        id: 4
      },
      {
        img1: '../../images/img1.png',
        img: '../../images/img.png',
        id: 5
      },
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var billid = options.billid
    var resid = options.resid
    console.log(billid,resid)
    this.setData({
      billid: billid,
      resid: resid
    })
    isShow: (options.isShow == "true" ? true : false)
    var that = this
  },

  selectStartFu: function(e) {
    var that = this
    var id = e.currentTarget.dataset.id
    that.setData({
      flag3: id
    })
    if (that.data.flag3 == 0) {
      that.setData({
        haoping2: '不满意'
      })
    }
    if (that.data.flag3 == 1) {
      that.setData({
        haoping2: '一般'
      })
    }
    if (that.data.flag3 == 2) {
      that.setData({
        haoping2: '满意'
      })
    }
    if (that.data.flag3 == 3) {
      that.setData({

        haoping2: '很满意'
      })
    }
    if (that.data.flag3 == 4) {
      that.setData({
        haoping2: '非常满意'
      })
    }

    console.log(id)
  },

  //好评

  //文本框
  bindTextAreaBlur: function(e) {
    var that = this
    var text = e.detail.value
    console.log(text)
    that.setData({
      textA: text
    })
  },
  // chooseImage: function() {
  //   var _this = this,
  //     pics = this.data.pics;
  //   wx.chooseImage({
  //     count: 9 - pics.length, // 最多可以选择的图片张数，默认9
  //     sizeType: ['original', 'compressed'], // original 原图，compressed 压缩图，默认二者都有
  //     sourceType: ['album', 'camera'], // album 从相册选图，camera 使用相机，默认二者都有
  //     success: function(res) {
  //       var imgSrc = res.tempFilePaths;
  //       console.log(imgSrc[0])
  //       wx.uploadFile({
  //         url: app.url.saveimg,
  //         filePath: res.tempFilePaths[0],
  //         name: 'file',
  //         header: { "Content-Type": "multipart/form-data" },
  //         success: function(res) {
  //           console.log(res)
  //           _this.setData({
  //             localImg: res.data
  //           })
  //         }
  //       })
  //       pics = pics.concat(imgSrc);
  //       console.log(pics)
  //       // 控制触发添加图片的最多时隐藏
  //       if (pics.length >= 4) {
  //         _this.setData({
  //           isShow: (!_this.data.isShow)
  //         })
  //         wx.showToast({
  //           title: '最多上传三张',
  //         })
  //         return false;
  //       } else {
  //         _this.setData({
  //           isShow: (_this.data.isShow)
  //         })
  //       }
  //       _this.setData({
  //         pics: pics
  //       })
  //     },
  //     fail: function() {
  //       // fail
  //     },
  //     complete: function() {
  //       // complete
  //     }
  //   })
  // },
  //提交


  //提交
  upload() {
    app.post(app.url.secCommentsave, {
      restaurantId: this.data.resid,
      comment: this.data.textA,
      score: this.data.flag3,
      userId: app.globalDataO.openid.objectSid,
      billId: this.data.billid,
      image:""
    }).then(res=>{
      console.log(res)
      if(res.data.code==0){
        wx.showToast({
          title: '评价成功',
          success(){
            wx.switchTab({
              url: '../../pages/orderlist/orderlist?status=10' +'&name=topay',
            })
          }
        })
      }
    })


  },
  // 图片预,览
  // previewImage: function(e) {
  //   var current = e.target.dataset.src
  //   wx.previewImage({
  //     current: current,
  //     urls: this.data.pics
  //   })
  // },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */


  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})